package com.mentaleye.dal.dao.mybatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.mentaleye.dal.dao.DormitoryStudentDao;
import com.mentaleye.dal.model.DormitoryStudent;
import com.mentaleye.dal.model.DormitoryStudentExample;
import com.mentaleye.dal.service.DormitoryStudentMapper;
@Repository
public class DormitoryStudentDaoImpl extends BaseDao implements DormitoryStudentDao {

	@Autowired private DormitoryStudentMapper dormitoryStudentMapper;
	@Override
	public boolean insertDormitoryStudent(DormitoryStudent dormitoryStudent) {
		return getResultByInt(dormitoryStudentMapper.insertSelective(dormitoryStudent));
	}

	@Override
	public boolean modifyDormitoryStudent(DormitoryStudent dormitoryStudent) {
		return getResultByInt(dormitoryStudentMapper.updateByPrimaryKeySelective(dormitoryStudent));
	}

	@Override
	public boolean deleteDorStudent(Integer stuId,Integer dorId) {
		DormitoryStudentExample example = new DormitoryStudentExample();
		example.createCriteria().andStuIdEqualTo(stuId).andDorIdEqualTo(dorId);
		return getResultByInt(dormitoryStudentMapper.deleteByExample(example));
	}

	@Override
	public List<DormitoryStudent> queryAllDormitory(DormitoryStudentExample example) {
		return dormitoryStudentMapper.selectByExample(example);
	}

	@Override
	public List<DormitoryStudent> queryDormitoryStudentById(Integer id) {
		return dormitoryStudentMapper.selectDormitoryStudentById(id);
	}

	@Override
	public int queryStudentCountByDorId(Integer dorId) {
		return dormitoryStudentMapper.selectStudentCountInDormitory(dorId);
	}

	@Override
	public boolean isExistRelate(Map<String, Object> map) {
		return getResultByInt(dormitoryStudentMapper.selectByDorStuMap(map));
	}

	@Override
	public DormitoryStudent queryDormitoryStudentByStuId(Integer stuId) {
		return dormitoryStudentMapper.selectDormitoryByStuId(stuId);
	}

	@Override
	public boolean deleteDormitoryStudent(Integer stuId, Integer status) {
		DormitoryStudentExample example = new DormitoryStudentExample();
		example.createCriteria().andStuIdEqualTo(stuId).andStayStatusEqualTo(status);
		return getResultByInt(dormitoryStudentMapper.deleteByExample(example));
	}

	@Override
	public List<Map<String, Object>> queryMap(Map<String, Object> map) {
		
		return dormitoryStudentMapper.selectMap(map);
	}

	@Override
	public DormitoryStudent queryDorStudentByStuIdAndDor(Integer stuId, Integer dorId, Integer stayStatus) {
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("stuId", stuId);
		map.put("dorId", dorId);
		map.put("stayStatus", stayStatus);
		return dormitoryStudentMapper.selectDorStudentByStuIdAndDor(map);
	}

}
